/**
 * Created by liaoxd on 2017/12/16.
 */
define([
  './themes/lang/' + window.YUFP_SYS_CONFIG.language + '/pages/content/systemManager/lookupdict/lookupdict.js',
  './custom/widgets/js/yufpOrgTree.js',
  './custom/widgets/js/yufpExtTree.js'
], function (require, exports) {
  // page加载完成后调用ready方法
  exports.ready = function (hashCode, data, cite) {
    var vm = yufp.custom.vue({
      el: '#lookupdictdiv',
      data: function () {
        var me = this;
        // 排序校验
        var orderValidate = function (rule, value, callback) {
          var reg = /^\d{0,4}$/;
          if (!reg.test(value)) {
            callback(new Error(me.$t('lookupdict.qsrzs09')));
            return;
          }
          callback();
        };
        return {
          filterFormdata: {},
          itemFormdata: {},
          // 类别目录url
          typeUrl: backend.appCommonService + '/api/adminsmlookuptype/list',
          // 类别表格url
          typetableUrl: backend.appCommonService + '/api/adminsmLookup/',
          // 内容url
          itemUrl: backend.appCommonService + '/api/adminsmlookupitem/',
          lookUpCodeUpdate: false,
          tableColumns: [{
            label: this.$t('lookupdict.zdlbywbm'),
            prop: 'lookupCode',
            sortable: true,
            resizable: true
          },
          {
            label: this.$t('lookupdict.zdlbmc'),
            prop: 'lookupName'
          }
          ],


          updateFields: [{
            columnCount: 1,
            fields: [{
              field: 'lookupCode',
              label: this.$t('lookupdict.lbywbm'),
              rules: [{
                required: true,
                message: this.$t('lookupdict.btx'),
                trigger: 'blur'
              },
              {
                max: 50,
                message: this.$t('lookupdict.zdcdbcggywzf'),
                trigger: 'blur'
              }
              ]
            },
            {
              field: 'lookupName',
              label: this.$t('lookupdict.zdlbmc'),
              rules: [{
                required: true,
                message: this.$t('lookupdict.btx'),
                trigger: 'blur'
              },
              {
                max: 100,
                message: this.$t('lookupdict.zdcdbcggzwzf'),
                trigger: 'blur'
              }
              ]
            }
            ]
          }],
          updateButtons: [{
            label: this.$t('lookupdict.bc'),
            type: 'primary',
            hidden: false,
            op: 'submit',
            click: function (model, valid) {
              if (valid) {
                model.lastChgUsr = me.userId;
                me.createFilter(model);
              }
            }
          },
          {
            label: this.$t('lookupdict.bc'),
            type: 'primary',
            hidden: false,
            op: 'submit',
            click: function (model, valid) {
              if (valid) {
                model.lastChgUsr = me.userId;
                me.lookuptableUpdateFn(model);
              }
            }
          },
          {
            label: this.$t('lookupdict.qx'),
            hidden: false,
            click: function (model) {
              me.dialogVisible = false;
            }
          }
          ],
          lookupTypeFields: [{
            columnCount: 1,
            fields: [{
              field: 'lookupTypeName',
              label: this.$t('lookupdict.mlmc'),
              rules: [{
                required: true,
                message: this.$t('lookupdict.btx'),
                trigger: 'blur'
              },
              {
                max: 50,
                message: this.$t('lookupdict.zdcdbcggzwzf'),
                trigger: 'blur'
              }
              ]
            },
            {
              field: 'upLookupTypeName',
              label: this.$t('lookupdict.sjml'),
              readonly: true,
              rules: [{
                required: true,
                message: this.$t('lookupdict.btx'),
                trigger: 'blur'
              }]
            }
            ]
          }],
          lookupTypeButtons: [{
            label: this.$t('lookupdict.bc'),
            type: 'primary',
            hidden: false,
            op: 'submit',
            click: function (model, valid) {
              if (valid) {
                model.lastChgUsr = me.userId;
                me.saveLookUpType(model);
                me.lkTypeDialogVisible = false;
              }
            }
          },
          {
            label: this.$t('lookupdict.bc'),
            type: 'primary',
            hidden: false,
            op: 'submit',
            click: function (model, valid) {
              if (valid) {
                model.lastChgUsr = me.userId;
                me.updateLookUpType(model);
                me.lkTypeDialogVisible = false;
              }
            }
          },
          {
            label: this.$t('lookupdict.qx'),
            hidden: false,
            click: function (model) {
              me.lkTypeDialogVisible = false;
            }
          }
          ],

          queryItemFields: [{
            placeholder: this.$t('lookupdict.zddmhmc'),
            field: 'lookupItemName',
            type: 'input'
          }],
          queryItemButtons: [
            {
              label: this.$t('lookupdict.ss'),
              op: 'submit',
              type: 'primary',
              click: function (model, valid) {
                if (valid) {
                  if (me.lookupItem.lookupCode) {
                    model.lookupCode = me.lookupItem.lookupCode ? me.lookupItem.lookupCode : null;
                  }
                  var param = {
                    condition: JSON.stringify(model),
                    sort: 'lookup_item_order asc'
                  };
                  me.$refs.itemTable.remoteData(param);
                }
              }
            },
            {
              label: this.$t('lookupdict.zz'),
              op: 'reset'
            }
          ],
          // 内容TABLE
          itemColumns: [{
            label: this.$t('lookupdict.zddm'),
            prop: 'lookupItemCode',
            sortable: true,
            resizable: true
          },
          {
            label: this.$t('lookupdict.zdmc'),
            prop: 'lookupItemName'
          },
          {
            label: this.$t('lookupdict.zdpx'),
            prop: 'lookupItemOrder'
          },
          {
            label: this.$t('lookupdict.zdbzsm'),
            prop: 'lookupItemComment'
          }
          ],
          lookupItemFields: [{
            columnCount: 1,
            fields: [{
              field: 'lookupItemCode',
              label: this.$t('lookupdict.zddm'),
              rules: [{
                required: true,
                message: this.$t('lookupdict.btx'),
                trigger: 'blur'
              },
              {
                max: 50,
                message: this.$t('lookupdict.zdcdbcggywzf'),
                trigger: 'blur'
              }
              ]
            },
            {
              field: 'lookupItemName',
              label: this.$t('lookupdict.zdmc'),
              rules: [{
                required: true,
                message: this.$t('lookupdict.btx'),
                trigger: 'blur'
              },
              {
                max: 50,
                message: this.$t('lookupdict.zdcdbcggzwzf'),
                trigger: 'blur'
              }
              ]
            },
            {
              field: 'lookupItemOrder',
              label: this.$t('lookupdict.zdbzsm'),
              rules: [
                { validator: orderValidate, trigger: 'blur' }
              ]
            },
            {
              field: 'lookupCode',
              label: this.$t('lookupdict.lbywbm'),
              readonly: true,
              rules: [{
                required: true,
                message: this.$t('lookupdict.btx'),
                trigger: 'blur'
              }]
            },
            {
              field: 'lookupItemComment',
              label: this.$t('lookupdict.zdbzsm')
            }
            ]
          }],
          lookupItemButtons: [{
            label: this.$t('lookupdict.bc'),
            type: 'primary',
            op: 'submit',
            hidden: false,
            click: function (model, valid) {
              if (valid) {
                model.lastChgUsr = me.userId;
                me.saveLookUpItem(model);
              }
            }
          },
          {
            label: this.$t('lookupdict.bc'),
            type: 'primary',
            op: 'submit',
            hidden: false,
            click: function (model, valid) {
              if (valid) {
                model.lastChgUsr = me.userId;
                me.updateLookUpItem(model);
              }
            }
          },
          {
            label: this.$t('lookupdict.qx'),
            hidden: false,
            click: function (model) {
              me.lkItemDialogVisible = false;
            }
          }

          ],
          userId: yufp.session.userId,
          // 表单是否显示
          dialogVisible: false,
          // 表单是否可用
          formDisabled: false,
          // 类别表单操作状态
          viewType: 'DETAIL',
          // 类别目录
          lktypeviewType: 'DETAIL',
          // 内容
          lkItemviewType: 'DETAIL',
          lookupTypeFormDisabled: false,
          lookupItemFormDisabled: false,

          styleObj: {
            height: yufp.custom.viewSize().height + 'px',
            overflow: 'auto'
          },
          height: yufp.custom.viewSize().height - 208,
          mheight: yufp.custom.viewSize().height - 268,
          // 目录FORM表单
          lkTypeDialogVisible: false,
          // 内容目录FORM表单
          lkItemDialogVisible: false,
          // 当前点击目录ID
          parentTypeId: null,
          // 当前选中目录ID
          currentTypeId: null,
          // 当前选中目录label
          currentTypeName: null,
          // 当前选中目录数据
          currentTypeData: null,
          // 当前目录level
          currentTypeLevel: null,
          // 当前选中内容目录ID
          currentItemId: null,
          // 表格类型目录ID不显示
          lookuptypids: false,
          idView: false,
          // 类别树过滤
          filterText: '',
          // 内容树过滤
          itemText: '',

          // 类别目录表单
          lookupType: {
            lookupTypeId: '',
            lookupTypeName: '',
            upLookupTypeId: '',
            upLookupTypeName: '',
            lastChgUsr: '',
            lastChgDt: ''
          },
          // 内容目录表单
          lookupItem: {
            lookupItemId: '',
            lookupItemCode: '',
            lookupItemName: '',
            lookupCode: '',
            upLookupItemId: '',
            lookupItemComment: '',
            lastChgUsr: '',
            lastChgDt: '',
            lookupItemOrder: ''
          },

          filterGrid: {
            // 当前类别行
            currentRow: null,
            // 当前内容行
            currentItemRow: null,

            data: null,
            total: null,
            loading: false,
            multipleSelection: '',
            // 多选类别
            selections: [],
            paging: {
              page: 1,
              pageSize: 10
            },
            // 类别TABLE模糊查询表头
            query: {
              lookupName: '',
              lookupCode: '',
              lookupTypeId: ''
            },
            lookup: {
              lookupId: '',
              lookupTypeId: '',
              lookupName: '',
              lastChgUsr: '',
              lastChgDt: ''
            }
          },
          lookuptypetree: {
            data: [{
              id: 0,
              label: '',
              children: []
            }],
            props: {
              children: 'children',
              label: 'label'
            }
          },
          itemTable: {
            data: [{
              id: 0,
              label: '',
              children: []
            }],
            props: {
              children: 'children',
              label: 'label'
            }
          }
        };
      },
      methods: {
        startChangeFn: function (val) {
          this.filterGrid.paging.page = val;
          this.queryInitFn();
        },
        limitChangeFn: function (val) {
          this.filterGrid.paging.page = 1;
          this.filterGrid.paging.pageSize = val;
          this.queryInitFn();
        },
        // 类别目录过滤搜索
        filterNode: function (value, data) {
          if (!value) {
            return true;
          }
          return data.label.indexOf(value) !== -1;
        },
        // 内容目录过滤搜索
        itemNode: function (value, data) {
          if (!value) {
            return true;
          }
          return data.label.indexOf(value) !== -1;
        },
        // 点击内容目录
        itemClickFn: function (row, event, column) {
          // 用于单个修改
          this.filterGrid.currentItemRow = row;
        },
        // 点击类别目录
        nodeClickFn: function (obj, node, nodeComp) {
          this.currentTypeId = node.data.id;
          this.currentTypeName = node.data.label;
          this.currentTypeData = node.data;
          this.currentTypeLevel = node.level;
          // 获取数据字典类别TABLE start
          var me = this;
          me.filterGrid.loading = true;
          var param = {
            page: me.filterGrid.paging.page,
            pageSize: me.filterGrid.paging.pageSize,
            condition: JSON.stringify({
              lookupTypeId: node.data.pid == '0000' ? null : this.currentTypeId // 如果点击根节点，清空条件，查询所有数据字典
            })
          };
          me.$refs.filterTable.remoteData(param);
          // 获取数据字典类别TABLE  end
        },

        // 新增类别目录树按钮
        createLkType: function () {
          if (this.currentTypeId == null) {
            vm.$message({
              message: vm.$t('lookupdict.qxzmljd'),
              type: 'warning'
            });
            return false;
          }

          // 挂在当前选中目录下面
          this.lookupType.upLookupTypeId = this.currentTypeId;
          this.lookupType.upLookupTypeName = this.currentTypeName;
          this.lkTypeDialogVisible = true;
          this.lktypeviewType = 'ADD';
          this.$nextTick(function () {
            this.$refs.lookupTypeForm.resetFields();
            this.$refs.lookupTypeForm.formModel.upLookupTypeId = this.currentTypeId;
            this.$refs.lookupTypeForm.formModel.upLookupTypeName = this.currentTypeName;
          });
        },
        // 修改类别目录树按钮
        updateLkType: function () {
          var lkTypeId = this.currentTypeId;
          if (lkTypeId == null) {
            this.$message({
              message: this.$t('lookupdict.qxzmljd'),
              type: 'warning'
            });
            return false;
          }
          if (this.currentTypeLevel == 1) {
            this.$message({
              message: this.$t('lookupdict.mlgjdbzcxg'),
              type: 'warning'
            });
            return false;
          }
          this.lktypeviewType = 'UPDATE';
          this.$nextTick(function () {
            this.$refs.lookupTypeForm.formModel = yufp.extend({}, this.currentTypeData);
          });
          this.lkTypeDialogVisible = true;
        },
        // 新增数据字典内容按钮
        createLkItem: function () {
          // 挂在当前选中目录下面
          if (this.filterGrid.currentRow == null) {
            vm.$message({
              message: vm.$t('lookupdict.qxzlb'),
              type: 'warning'
            });
            return false;
          }
          this.lookupItem.lookupCode = this.filterGrid.currentRow.lookupCode;
          this.lkItemDialogVisible = true;
          this.lkItemviewType = 'ADD';
          this.$nextTick(function () {
            this.$refs.lookupItemForm.resetFields();
            this.$refs.lookupItemForm.formModel.lookupCode = this.filterGrid.currentRow.lookupCode;
          });
        },
        // 修改数据字典内容按钮
        updateLkItem: function () {
          var currentItemRow = this.$refs.itemTable.selections;
          if (currentItemRow.length != 1) {
            vm.$message({
              message: vm.$t('lookupdict.qxzsjzdnr'),
              type: 'warning'
            });
            return false;
          }

          this.lkItemviewType = 'UPDATE';
          this.$nextTick(function () {
            this.$refs.lookupItemForm.formModel = yufp.extend({}, currentItemRow[0]);
          });
          this.lkItemDialogVisible = true;
        },
        // 新增目录保存
        saveLookUpType: function (model) {
          model.instuId = yufp.session.instu.code;
          this.lookupType = model;
          delete this.lookupType.lookupTypeId;
          yufp.service.request({
            url: backend.appCommonService + '/api/adminsmlookuptype/',
            method: 'post',
            data: this.lookupType,
            callback: function (code, message, response) {
              if (code == '0') {
                vm.$message({
                  message: vm.$t('lookupdict.bccg')
                });
                vm.lkTypeDialogVisible = false;
                // 刷新树
                vm.$refs.lookuptypetree.remoteData();
              } else {
                vm.$message({
                  message: vm.$t('lookupdict.bcsb')
                });
              }
            }
          });
        },
        // 修改目录保存
        updateLookUpType: function (model) {
          this.lookupType = model;
          yufp.service.request({
            url: backend.appCommonService + '/api/adminsmlookuptype/updates',
            method: 'post',
            data: this.lookupType,
            callback: function (code, message, response) {
              if (code == '0') {
                vm.$message({
                  message: vm.$t('lookupdict.bccg')
                });
                vm.lkTypeDialogVisible = false;
                // 刷新树
                vm.$refs.lookuptypetree.remoteData();
              } else {
                vm.$message({
                  message: vm.$t('lookupdict.bcsb')
                });
              }
            }
          });
        },
        // 新增数据字典内容保存
        saveLookUpItem: function (model) {
          this.lookupItem = model;
          this.lookupItem.upLookupItemId = '';
          delete this.lookupItem.lookupItemId;
          yufp.service.request({
            url: backend.appCommonService + '/api/adminsmlookupitem/createitem',
            method: 'post',
            data: this.lookupItem,
            callback: function (code, message, response) {
              if (code == '0') {
                vm.$message({
                  message: vm.$t('lookupdict.bccg')
                });
                vm.lkItemDialogVisible = false;
                var param = {
                  page: 0,
                  pageSize: 100,
                  condition: JSON.stringify({
                    lookupCode: vm.lookupItem.lookupCode
                  })
                };
                // 刷新树
                vm.$refs.itemTable.remoteData(param);
              } else {
                vm.$message({
                  message: vm.$t('lookupdict.bcsb')
                });
              }
            }
          });
        },
        // 修改数据字典内容保存
        updateLookUpItem: function (model) {
          this.lookupItem = model;
          yufp.service.request({
            url: backend.appCommonService + '/api/adminsmlookupitem/updates',
            method: 'post',
            data: this.lookupItem,
            callback: function (code, message, response) {
              if (code == '0') {
                vm.$message({
                  message: vm.$t('lookupdict.bccg')
                });
                vm.lkItemDialogVisible = false;
                var param = {
                  page: 0,
                  pageSize: 100,
                  condition: JSON.stringify({
                    lookupCode: vm.lookupItem.lookupCode
                  })
                };
                // 刷新树
                vm.$refs.itemTable.remoteData(param);
              } else {
                vm.$message({
                  message: vm.$t('lookupdict.bcsb')
                });
              }
            }
          });
        },
        // 删除类别目录树
        deleteLkType: function () {
          var lookupTypeId = this.currentTypeId;

          if (lookupTypeId == null) {
            vm.$message({
              message: vm.$t('lookupdict.qxzmljd'),
              type: 'warning'
            });
            return false;
          }

          var nodeData = this.currentTypeData;

          var getAllId = function (node, arr) {
            arr.push(node.id);
            var cList = node.children;
            if (cList && cList.length > 0) {
              for (var i in cList) {
                getAllId(cList[i], arr);
              }
            } else {
              return;
            }
          };

          var arr = [];
          getAllId(nodeData, arr);
          vm.$confirm(vm.$t('lookupdict.qrscglbmlyjmlxdlb'), vm.$t('lookupdict.ts'), {
            confirmButtonText: vm.$t('lookupdict.qd'),
            cancelButtonText: vm.$t('lookupdict.qx'),
            type: 'warning'
          }).then(function () {
            yufp.service.request({
              url: backend.appCommonService + '/api/adminsmlookuptype/deletes',
              method: 'post',
              data: JSON.stringify(arr),
              callback: function (code, message, response) {
                if (code == '0') {
                  vm.$message({
                    message: vm.$t('lookupdict.sccg')
                  });
                  // 刷新树
                  vm.$refs.lookuptypetree.remoteData();
                  vm.$refs.filterTable.remoteData();
                  vm.$refs.itemTable.remoteData();
                } else {
                  vm.$message({
                    message: vm.$t('lookupdict.scsb')
                  });
                }
              }

            });
          });
        },
        // 删除数据字典内容
        deleteLkItem: function () {
          var currentItemRow = this.$refs.itemTable.selections;
          if (currentItemRow.length != 1) {
            vm.$message({
              message: vm.$t('lookupdict.qxzsjzdnr'),
              type: 'warning'
            });
            return false;
          }
          var lookupItem = JSON.stringify({
            lookupItemId: currentItemRow[0].lookupItemId,
            lookupCode: currentItemRow[0].lookupCode
          });
          vm.$confirm(vm.$t('lookupdict.qrscgzdnr'), vm.$t('lookupdict.ts'), {
            confirmButtonText: vm.$t('lookupdict.qd'),
            cancelButtonText: vm.$t('lookupdict.qx'),
            type: 'warning'
          }).then(function () {
            yufp.service.request({
              url: backend.appCommonService + '/api/adminsmlookupitem/delete',
              method: 'POST',
              data: lookupItem,
              callback: function (code, message, response) {
                if (code == '0') {
                  vm.$message({
                    message: vm.$t('lookupdict.sccg')
                  });
                  // 刷新树
                  var param = {
                    page: 0,
                    pageSize: 100,
                    condition: JSON.stringify({
                      lookupCode: currentItemRow[0].lookupCode
                    })
                  };
                  // 刷新树
                  vm.$refs.itemTable.remoteData(param);
                } else {
                  vm.$message({
                    message: vm.$t('lookupdict.scsb')
                  });
                }
              }

            });
          });
        },
        //    ---------------------------------字典类别表格操作 start------------------------------------------
        rowClickFn: function (row, event, column) {
          // 用于单个修改
          this.filterGrid.currentRow = row;
          this.lookupItem.lookupCode = row.lookupCode;
          // 获取内容目录 start
          var param = {
            page: 0,
            pageSize: 100,
            sort: 'lookup_item_order asc',
            condition: JSON.stringify({
              lookupCode: this.filterGrid.currentRow.lookupCode
            })
          };
          vm.$refs.itemTable.remoteData(param);
          // 获取内容目录 end
        },

        // 通过typeId初始化查询类别TABLE
        queryInitFn: function () {
          var me = this;
          me.filterGrid.loading = true;
          var param = {
            page: me.filterGrid.paging.page,
            pageSize: me.filterGrid.paging.pageSize,
            condition: JSON.stringify({
              lookupTypeId: this.currentTypeData.pid == '0000' ? null : this.currentTypeId
            })
          };
          // 发起请求
          me.$refs.filterTable.remoteData(param);
        },
        // 修改字典类别按钮
        lookuptableEditFn: function () {
          var currentRow = this.$refs.filterTable.selections;
          if (currentRow.length != 1) {
            vm.$message({
              message: vm.$t('lookupdict.qxzytzdlbjl'),
              type: 'warning'
            });
            return false;
          }
          this.viewType = 'UPDATE';
          vm.dialogVisible = true;
          this.$nextTick(function () {
            this.$refs.datafilterForm.switch('lookupCode', 'readonly', true);
            this.$refs.datafilterForm.formModel = yufp.extend({}, currentRow[0]);
          });
        },
        // 修改字典类别保存
        lookuptableUpdateFn: function (row) {
          this.filterGrid.currentRow = row;

          yufp.service.request({
            url: backend.appCommonService + '/api/adminsmLookup/updates',
            method: 'post',
            data: this.filterGrid.currentRow,
            callback: function (code, message, response) {
              if (code == '0') {
                vm.$message({
                  message: vm.$t('lookupdict.bccg')
                });
                vm.queryInitFn();
                vm.dialogVisible = false;
                vm.$refs.filterTable.remoteData();
              } else {
                vm.$message({
                  message: vm.$t('lookupdict.xgsb')
                });
              }
            }
          });
        },
        // 增加字典类别按钮
        addFilterRecord: function () {
          if (this.currentTypeId === null) {
            vm.$message({
              message: vm.$t('lookupdict.qxzml'),
              type: 'warning'
            });
            return false;
          }
          this.dialogVisible = true;
          this.viewType = 'ADD';
          this.$nextTick(function () {
            this.$refs.datafilterForm.resetFields();
            this.$refs.datafilterForm.switch('lookupCode', 'readonly', false);
            this.$refs.datafilterForm.formModel.lookupTypeId = this.currentTypeId;
          });
        },

        // 保存新增字典类别
        createFilter: function (row) {
          this.filterGrid.currentRow = row;
          delete this.filterGrid.currentRow.lookupId;
          yufp.service.request({
            url: backend.appCommonService + '/api/adminsmLookup/createvalidate',
            method: 'post',
            data: this.filterGrid.currentRow,
            callback: function (code, message, response) {
              if (code == '0') {
                if (response.code == 20100002) {
                  vm.$message({
                    message: response.message,
                    type: 'warning'
                  });
                  return false;
                } else {
                  vm.$message({
                    message: vm.$t('lookupdict.bccg')
                  });
                  vm.queryInitFn();
                  vm.dialogVisible = false;
                  vm.$refs.filterTable.remoteData();
                }
              } else {
                vm.$message({
                  message: vm.$t('lookupdict.bcsb')
                });
              }
            }
          });
        },
        // 删除数据字典类别
        dataFilterDeleteFn: function (row) {
          this.filterGrid.currentRow = row;
          vm.$confirm(vm.$t('lookupdict.qrscgsjzdlb'), vm.$t('lookupdict.ts'), {
            confirmButtonText: vm.$t('lookupdict.qd'),
            cancelButtonText: vm.$t('lookupdict.qx'),
            type: 'warning'
          }).then(function () {
            yufp.service.request({
              url: backend.appCommonService + '/api/adminsmLookup/delete/' + this.filterGrid.currentRow.lookupId,
              method: 'post',
              data: null,
              callback: function (code, message, response) {
                if (code == '0') {
                  vm.$message({
                    message: vm.$t('lookupdict.sccg')
                  });
                  vm.queryInitFn();
                  vm.$refs.itemTable.remoteData();
                } else {
                  vm.$message({
                    message: vm.$t('lookupdict.scsb')
                  });
                }
              }
            });
          });
        },
        // 批量删除数据字典类别
        dataFiltermultDeleteFn: function () {
          var currentRow = this.$refs.filterTable.selections;
          if (currentRow.length != 1) {
            vm.$message({
              message: vm.$t('lookupdict.qxzytzdlbjl'),
              type: 'warning'
            });
            return false;
          }
          vm.$confirm(vm.$t('lookupdict.qrscgzdlbyjlbxdzdnr'), vm.$t('lookupdict.ts'), {
            confirmButtonText: vm.$t('lookupdict.qd'),
            cancelButtonText: vm.$t('lookupdict.qx'),
            type: 'warning'
          }).then(function () {
            yufp.service.request({
              url: backend.appCommonService + '/api/adminsmLookup/deletes/' + currentRow[0].lookupId,
              method: 'post',
              data: {
                lookupId: currentRow[0].lookupId
              },
              callback: function (code, message, response) {
                if (code == '0') {
                  vm.$message({
                    message: vm.$t('lookupdict.sccg')
                  });
                  vm.queryInitFn();
                  vm.$refs.itemTable.remoteData();
                } else {
                  vm.$message({
                    message: vm.$t('lookupdict.scsb')
                  });
                }
              }
            });
          });
        },
        //    ---------------------------------字典类别表格操作 end------------------------------------------
        /**
         *  批量更新数据字典缓存
         * 仅用于非页面操作时更新Redis缓存。可能较慢。
         * 当某个字典更新失败会提示对应code信息，请尝试手动更新。
         */
        refreshLkItem: function () {
          var _this = this;
          yufp.service.request({
            method: 'GET',
            url: backend.appCommonService + '/api/adminsmlookupitem/refreshitem',
            timeout: 20000,
            callback: function (code, message, response) {
              if (code == 0 && response.code == 20100000) {
                _this.$message({
                  message: response.message
                });
              } else {
                _this.$message({
                  message: _this.$t('lookupdict.sjzdhcgxsb'),
                  type: 'warning'
                });
              }
            }

          });
        }
      },
      watch: {
        filterText: function (value) {
          vm.$refs.lookuptypetree.filter(value);
        },
        viewType: function (value) {
          if (value == 'ADD') {
            this.lookUpCodeUpdate = false;
            this.updateButtons[0].hidden = false;
            this.updateButtons[1].hidden = true;
          } else if (value == 'UPDATE') {
            this.lookUpCodeUpdate = true;
            this.updateButtons[0].hidden = true;
            this.updateButtons[1].hidden = false;
          } else if (value == 'DETAIL') {
            this.updateButtons[0].hidden = true;
            this.updateButtons[1].hidden = true;
          }
        },
        lktypeviewType: function (value) {
          if (value == 'ADD') {
            this.lookupTypeButtons[0].hidden = false;
            this.lookupTypeButtons[1].hidden = true;
          } else if (value == 'UPDATE') {
            this.lookupTypeButtons[0].hidden = true;
            this.lookupTypeButtons[1].hidden = false;
          } else if (value == 'DETAIL') {
            this.lookupTypeButtons[0].hidden = true;
            this.lookupTypeButtons[1].hidden = true;
          }
        },
        lkItemviewType: function (value) {
          if (value == 'ADD') {
            this.lookupItemButtons[0].hidden = false;
            this.lookupItemButtons[1].hidden = true;
          } else if (value == 'UPDATE') {
            this.lookupItemButtons[0].hidden = true;
            this.lookupItemButtons[1].hidden = false;
          } else if (value == 'DETAIL') {
            this.lookupItemButtons[0].hidden = true;
            this.lookupItemButtons[1].hidden = true;
          }
        }

      }

    });
  };

  // 消息处理
  exports.onmessage = function (type, message) {

  };

  // page销毁时触发destroy方法
  exports.destroy = function (id, cite) {

  };
});
